function stopBodyScroll(isFixed, that) {
	var bodyEl = document.body;
	if (isFixed) { //开启
		that._top = window.scrollY;
		bodyEl.style.position = 'fixed';
		bodyEl.style.top = -that._top + 'px';
	} else { //关闭
		bodyEl.style.position = 'relative';
		bodyEl.style.top = '';
		window.scrollTo(0, that._top); // 回到原先的top
	}
};

var $Box = {}

/**alert */
$Box.alert = {};
$Box.alert.stopBodyScroll = stopBodyScroll;
/**
 *  param
 *  
 *  text : '内容'
 * 
 *  isCancel: true/false 是否展示取消
 *  
 *  confirm 确认回调
 * 
 * 	cancel  取消回调
 * 
 * */

 $Box.alert.show = function(param) {
	this.alertMask = document.getElementById("alert-mask");
	this.stopBodyScroll(true, this);
  var text = param ? param.text || '' : ''
  var isCancel = param ? param.isCancel : false
	if (this.alertMask) {
		var dom = document.getElementById("alert-text");
		dom.innerHTML = text
		this.alertMask.style.display = "block";
	} else {
		this.alert = document.createElement("div");
		this.htmlCancel = '<div id="alert-mask" class="alert-mask"><div><div class="alert-inner"><div class="alert-title">提示</div><div id="alert-text" class="alert-text">'+ text +'</div></div><div class="alert-buttons"><div id="alert-then" class="alert-button alert-then">确定</div><div id="alert-catch" class="alert-button alert-catch">取消</div></div></div></div>'
		this.html = '<div id="alert-mask" class="alert-mask"><div><div class="alert-inner"><div class="alert-title">提示</div><div id="alert-text" class="alert-text">'+ text +'</div></div><div class="alert-buttons"><div id="alert-then" class="alert-button alert-then">确定</div></div></div></div>'
		this.alert.innerHTML = isCancel ? this.htmlCancel : this.html;
		document.body.appendChild(this.alert);
	};
	var alertThen = document.getElementById('alert-then');
	var alertCatch = document.getElementById('alert-catch');
	alertThen.onclick = function(){
		$Box.alert.hide()
		param && param.confirm && param.confirm()
	}
	if(alertCatch) {
		alertCatch.onclick = function(){
			$Box.alert.hide()
			param && param.cancel && param.cancel()
		}
	}
};
$Box.alert.hide = function() {
	this.stopBodyScroll(false, this);
	try {
		this.alertMask = document.getElementById("alert-mask");
		this.alertMask.style.display = "none";
	} catch (e) {};
};


/**loading */
$Box.loading = {};
$Box.loading.stopBodyScroll = stopBodyScroll;
$Box.loading.show = function(text) {
  text === undefined && (text = "正在加载")
	this.loadingMask = document.getElementById("loading-mask");
	this.stopBodyScroll(true, this);
	if (this.loadingMask) {
		this.loading.style.display = "block";
	} else {
		this.loading = document.createElement("div");
		this.str = "";
		for (var i = 0; i < 12; i++) {
			this.str += '<div class="loading_leaf loading_leaf_' + i + '"></div>'
		};
		this.html =
			'<div class="loading-mask" id="loading-mask"><div class="loading-wrapper"><div class="loading__loading-wrapper">' +
			this.str + '</div><div class="loading__loading-wrapper-text">' + text + '</div></div></div>'
		this.loading.innerHTML = this.html;
		document.body.appendChild(this.loading);
	};
};
$Box.loading.hide = function() {
	this.stopBodyScroll(false, this);
	try {
		this.loading.style.display = "none";
	} catch (e) {};
};

/**toast*/
$Box.toast = {};
$Box.toast.stopBodyScroll = stopBodyScroll;
/**
 *  param
 *  
 *  text : '内容'
 *  
 *  time : '几秒后消失'（单位毫秒） 默认1500 传0则不消失
 * 
 * */

 $Box.toast.show = function(param) {
  var text = param ? param.text || '' : ''
  var time = param ? param.time : 1500
	this.toastMask = document.getElementById("toast-mask");
	this.stopBodyScroll(true, this);
	if (this.toastMask) {
		var dom = document.getElementById("toast-text");
		dom.innerHTML = text
		this.toastMask.style.display = "block";
	} else {
		this.toast = document.createElement("div");
    this.toast.innerHTML = '<div id="toast-mask"><div class="toastMask"><div id="toast-text" class="toastText">'+ text +'</div></div></div>'
		document.body.appendChild(this.toast);
	};
  if(time !== 0) {
    var timer = setTimeout(function() {
      clearTimeout(timer)
      $Box.toast.hide()
    },time || 1500);
  }
};
$Box.toast.hide = function() {
	this.stopBodyScroll(false, this);
	try {
		this.toastMask = document.getElementById("toast-mask");
		this.toastMask.style.display = "none";
	} catch (e) {};
};

/**wxTip */
$Box.wxTip = {};
$Box.wxTip.imgSrc = '';
$Box.wxTip.stopBodyScroll = stopBodyScroll;

$Box.wxTip.show = function() {
	this.wxTipMask = document.getElementById("wxTip-mask");
	this.stopBodyScroll(true, this);
	if (this.wxTipMask) {
		this.wxTipMask.style.display = "block";
	} else {
    this.wxTipMask = document.createElement("div");
		this.wxTipMask.innerHTML = '<div id="wxTip-mask"><div class="wxTip"><img src="'+ $Box.wxTip.imgSrc +'"></div></div>'
    document.body.appendChild(this.wxTipMask);
	};
};
$Box.wxTip.hide = function() {
	this.stopBodyScroll(false, this);
	try {
		this.wxTipMask = document.getElementById("wxTip-mask");
		this.wxTipMask.style.display = "none";
	} catch (e) {};
};
